$(function () {
  // console.log(000);
  resetui()
  $('#btnSend').on('click', function () {
    const text = $('#ipt').val().trim();
    if (text.length <= 0) {
      $('#ipt').val('')
      return
    }
    $("#talk_list").append(`<li class="right_word">
    <img src="img/person02.png" /> <span>${text}</span>
  </li>`)
    resetui()
    $('#ipt').val('')
    getMsg(text)
  })
  function getMsg(text) {
    $.ajax({
      type: 'GET',
      data: {
        spoken: text
      },
      url: 'http://www.liulongbin.top:3006/api/robot',
      success: function (res) {
        console.log(res);
        if (res.message === 'success') {
          var mag = res.data.info.text;
          console.log(mag);
          $('#talk_list').append('<li class="left_word"><img src="img/person01.png" /> <span>' + mag + '</span></li>')
          resetui()
          getVoice(mag)
        }
      }
    })
  }
  function getVoice(text) {
    $.ajax({
      method: 'GET',
      url: 'http://www.liulongbin.top:3006/api/synthesize',
      data: {
        text: text
      },
      success: function (res) {
        console.log(res);
        if (res.status === 200) {
          $('#voice').attr('src', res.voiceUrl)
        }
      }
    })
  }
  $('#ipt').on('keyup', function (e) {
    if (e.keyCode === 13) {
      $('#btnSend').click()
    }
  })
})